export default function(state) {
  const addTodo = () => {
    state.todos.push({
      id: Math.random(),
      title: state.newTodo,
      completed: false
    })
    state.newTodo = ''
  }

  /**
   * 切换任务是否已做
   * @param {*} idx
   */
  const toggle = idx => {
    state.todos[idx].completed = !state.todos[idx].completed
  }

  return { addTodo, toggle }
}
